package com.qeado.content.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.qeado.common.helper.AttributeHelper;
import com.qeado.content.model.PlantArea;
import com.qeado.content.service.PlantAreaManageService;

@Controller
public class PlantAreaManageController {
	@Autowired
	private PlantAreaManageService plantAreaManageService;
	
	@RequestMapping("/plantAreaManage.ac")
	public String plantAreaManage(HttpServletRequest request) {
		AttributeHelper.removeSessionAttribute(request, "T_");
		List<PlantArea> plantTypeList = plantAreaManageService.getPlantTypeList();
		List<PlantArea> provinceList = plantAreaManageService.getProvinceList();
		request.getSession().setAttribute("T_plantTypeList", plantTypeList);
		request.getSession().setAttribute("T_provinceList", provinceList);
		return "content/plant_area_search";
	}

	@RequestMapping("/plantAreaSearch.ac")
	public String plantAreaSearch(HttpServletRequest request, PlantArea plantArea) {
		List<PlantArea> plantAreaList = plantAreaManageService.searchPlantArea(plantArea);
		request.setAttribute("plantAreaList", plantAreaList);
		return "content/plant_area_search";
	}

	@RequestMapping("/backToPlantAreaSearch.ac")
	public String backToPlantAreaSearch() {
		return "content/plant_area_search";
	}

	@RequestMapping("/newPlantArea.ac")
	public String newPlantArea() {
		return "content/plant_area_manage";
	}

	@RequestMapping("/selectPlantArea.ac")
	public String selectPlantArea(HttpServletRequest request, String id) {
		PlantArea plantArea = plantAreaManageService.searchPlantAreaById(id);
		request.setAttribute("plantArea", plantArea);
		return "content/plant_area_manage";
	}

	@RequestMapping("/deletePlantArea.ac")
	public String deletePlantArea(HttpServletRequest request, String id) {
		plantAreaManageService.deletePlantArea(id);
		List<PlantArea> plantAreaList = plantAreaManageService.searchPlantArea(null);
		request.setAttribute("plantAreaList", plantAreaList);
		return "content/plant_area_search";
	}

	@RequestMapping("/savePlantArea.ac")
	public String savePlantArea(HttpServletRequest request, PlantArea plantArea) {
		String message = plantAreaManageService.savePlantArea(plantArea);
		request.setAttribute("message", message);
		return "content/plant_area_manage";
	}

}
